package br.com.moxirpt.test.jbehave;

import java.util.Locale;

import org.jbehave.scenario.JUnitScenario;
import org.jbehave.scenario.PropertyBasedConfiguration;
import org.jbehave.scenario.definition.KeyWords;
import org.jbehave.scenario.errors.PendingErrorStrategy;
import org.jbehave.scenario.i18n.I18nKeyWords;
import org.jbehave.scenario.i18n.StringEncoder;
import org.jbehave.scenario.parser.ClasspathScenarioDefiner;
import org.jbehave.scenario.parser.PatternScenarioParser;
import org.jbehave.scenario.parser.ScenarioDefiner;
import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver;
import org.jbehave.scenario.reporters.PrintStreamScenarioReporter;
import org.jbehave.scenario.reporters.ScenarioReporter;

public class GenericScenario extends JUnitScenario {

	public GenericScenario() {
		this(Thread.currentThread().getContextClassLoader());
	}

	public GenericScenario(final ClassLoader classLoader) {
		super(new PropertyBasedConfiguration() {
			
			@Override
			public ScenarioDefiner forDefiningScenarios() {
				// use underscored camel case scenario files with extension ".cenario"
				return new ClasspathScenarioDefiner(
						new UnderscoredCamelCaseResolver(".cenario"),
						new PatternScenarioParser(this), classLoader);
			}

			
			@Override
			public PendingErrorStrategy forPendingSteps() {
				
				return PendingErrorStrategy.FAILING;
			}


			@Override
			public ScenarioReporter forReportingScenarios() {

				return new PrintStreamScenarioReporter(keywordsFor(new Locale("pt"), classLoader));
				
			}


			@Override
			public KeyWords keywords() {				
				return keywordsFor(new Locale("pt"), classLoader);
			}

			
			

		});
		
	}

	protected static KeyWords keywordsFor(Locale locale, ClassLoader classLoader) {
		return new I18nKeyWords(locale, new StringEncoder(), "br/com/moxirpt/test/jbehave/keywords", classLoader);
	}

	

	
}

